<template>
  <div slot>
    <v-card>
      <v-card-title primary-title>
        <div style="width: 100%">
          <h3 class="headline mb-0">填写资料</h3>
          <p>供应商名称</p>
          <v-select
            v-model="company_id"
            :items="company"
            label="请选择供应商"
            no-data-text="没有数据"
            item-text="company_name"
            item-value="id"
          ></v-select>
          <p>库存类型</p>
            <v-radio-group  v-model="action"  row>
              <v-radio label="进库" value="1"></v-radio>
              <v-radio label="出库" value="2"></v-radio>
            </v-radio-group>
          <p>日期</p>
          <v-date-picker v-model="picker" :landscape="landscape" :reactive="reactive"></v-date-picker>
          <v-text-field
            v-model="goods_name"
            :rules="nameRules"
            label="食品名称"
            required
          ></v-text-field>
          <v-text-field
            v-model="number"
            :rules="nameRules"
            label="数量"
            required
          ></v-text-field>
          <v-text-field
            v-model="username"
            :rules="nameRules"

            label="仓管姓名"
            required
          ></v-text-field>
          <v-text-field
            v-model="pici"
            :rules="nameRules"

            label="批次"
            required
          ></v-text-field>
          <p>生产日期</p>
          <v-date-picker v-model="made_date" :landscape="landscape" :reactive="reactive"></v-date-picker>
          <v-text-field
            v-model="remark"
            :rules="nameRules"

            label="备注"
            required
          ></v-text-field>
          <v-btn color="info" @click="save">保存</v-btn>

        </div>
      </v-card-title>
    </v-card>
  </div>
</template>

<script>
  export default {
    name: "MealEdit",
    created(){
      let myDate = new Date();
      this.picker = myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate()
      this.made_date = this.picker
    },
    mounted(){
      this.getCompany()
      this.meal_id = this.$route.params.id
      this.showMeal(this.meal_id)
    },
    methods:{
      getCompany(){
        let this_ = this
        this.axios.get('/index/company/getlist').then(function (res) {
        console.log(res.data.data)
          this_.company = res.data.data
        })
      },
      showMeal(id){
        let this_ = this
        this.axios.get('/index/meal/detail/id/'+this.meal_id).then(function (res) {
          this_.picker = res.data.data.intime
          this_.number = res.data.data.number
          this_.username = res.data.data.username
          this_.goods_name = res.data.data.goods_name
          this_.made_date = res.data.data.made_date
          this_.pici = res.data.data.pici
          this_.remark = res.data.data.remark
          this_.company_id = res.data.data.company_id
          if (res.data.data.action=='入库') {
              this_.action = '1'
          }else {
            this_.action = '2'
          }

        })
      },
      save(){
        let this_ = this

        this.axios.post('/index/meal/saveedit',{
          meal_id:this.meal_id,
          company_id:this.company_id,
          goods_name:this.goods_name,
          username:this.username,
          number:this.number,
          intime:this.picker,
          action:this.action,
          remark:this.remark,
          made_date:this.made_date,
          pici:this.pici


        }).then(function (res) {
          if (res.data.errno==0){
            alert('保存成功')
            this_.$router.push('/meal/show')
          } else{
            alert(res.data.msg)
          }
        })
      }
    },
    data () {
      return {
        action:'1',
        picker: null,
        landscape: true,
        reactive: true,
        company: [],
        company_id:0,
        username:'',//仓管姓名，
        number:0,//数量
        goods_name:'',//食品名称
        meal_id:0,
        made_date:null,
        pici:'',
        remark:'',
        nameRules: [
          v => !!v || '请填写内容',

        ],
      }
    }
  }
</script>

<style scoped>

</style>
